#!/usr/bin/perl

$argc = @ARGV;
if ($argc != 2)
{	print "Usage: ./genFilter.pl dir ext\n";
	exit(-1);	}

$dir = $ARGV[0];
$ext = $ARGV[1];

#ensures $dir ends with / 
if ($dir !~ m/.*\/$/)
{	$dir = $dir."/";	}

@flist = glob("$dir*.$ext");

foreach $x (<@flist>)
{
   chomp($x);
  
   print $x;
   
   
   @a = split(/\./, $x);
   #make directory for enhanced images if it doesn't already exist
   if (-e "filtered")
   {}
   else
   {	 system("mkdir filtered"); }
   
   #make a new filename to output as
   $nfname = $a[0].".bc";
   @b = split(/\//, $nfname);
   $rfname = "filtered/".$b[-1];
   
   print "$x\t->\t$rfname\n";
   system("./filter -f $x -o $rfname");


}
